<template>
	<div style="width:98%;margin:0 auto;">
		<div class="cardHead">
			<svg class="icon" aria-hidden="true">
				<use xlink:href="#icon-icon_mate"></use>
			</svg>
			<div class="text">最近文章</div>
		</div>
		<div class="ArtiList">
			<div class="Artiitem" v-for="(item,index) in dataList" :key="index" @click="goArticle(item.Id)">
				<div class="data">{{item.datetime}}</div>
				<div class="name">{{item.name}}</div>
			</div>
		</div>
	</div>
</template>

<script>
	import {} from '../../assets/font/iconfont.js'
	export default {
		name: 'Article',
		data() {
			return {
				dataList:[],	
			}
		},
		created() {},
		mounted() {
			this.getData();
		},
		methods: {
			// 拉取数据
			getData() {
				this.$axios.post(this.HOST + '/api/indexPage').then(res => {
					let data = res.data.data;
					for(let i= 0;i<data.length;i++) {
						let arr = {};
						arr.Id = data[i].Id;
						arr.name = data[i].name;
						arr.datetime = data[i].datetime.slice(0,10);
						var days = (Date.parse(new Date()) - Date.parse(data[i].datetime))/(1*24*60*60*1000);
						arr.days = days;
						if(days<100){this.dataList.push(arr)}
					}
					this.dataList.sort(function(a,b){
						return a.days - b.days
					});
				}).catch(err => {console.log(err,'catch')})
			},
			// 点击跳转goArticle
			goArticle(e) {
				let arr = {};
				arr.name = '最近文章';
				arr.ArtID = e;
				this.$emit("buttArticle",arr)
			},
			
		}
	}
</script>